Pass context to other models when fetching more data#69
Pass context to other models when fetching more data#69a-willem wants to merge 1 commit intoOCA:masterfrom
Conversation
| fields_get = self._odoo.execute(model, 'fields_get') | ||
| for field_name, field_data in fields_get.items(): | ||
| if field_name not in FIELDS_RESERVED: | ||
| field_data['context'] = self._context # pass context to new fields ... |
There was a problem hiding this comment.
Hi, thanks for contributing.
Could you please share the use case that need to add context to field data
There was a problem hiding this comment.
Hi @flotho,
In the following sample code (some bits are redundant, they're extracted from a longer chunk of code..), using a vanilla odoorpc==0.8.0, you will get term_id = False and fiscal_pos_id = False.
Using this proposed patch, you will get the id corresponding to the requested property, depending on the requested company_id.
creds['companyid'] = <sample company_id>
rp = odoo.env['res.partner']
rp_list = rp.with_context(allowed_company_ids=[creds['companyid']])
move_part = rp_list.browse([<sample partner_id>])
term_id = move_part.with_context(company=creds['companyid']).property_payment_term_id.id
fiscal_pos_id = move_part.with_context(company=creds['companyid']).property_account_position_id.id
There was a problem hiding this comment.
Hope my approach is the right one ! If I've missed something, don't hesitate to correct me.
Best regards,
Arnaud
There was a problem hiding this comment.
thanks, more clear and very useful
| fields_get = self._odoo.execute(model, 'fields_get') | ||
| for field_name, field_data in fields_get.items(): | ||
| if field_name not in FIELDS_RESERVED: | ||
| field_data['context'] = self._context # pass context to new fields ... |
There was a problem hiding this comment.
thanks, more clear and very useful
|
Why is this not merged yet ? |
When OdooRPC dynamically fetches more information (i.e. when accessing .partner_id.name), if the instance has been instantiated using
with_context, this context is not passed along and can lead to unwanted results (i.e when using with_context(allowed_company_ids=[1,2,3]))This fix allows to pass such context information.